#ifndef CHAIN_H
#define CHAIN_H
#include "javabean.h"
#include <iostream>
using namespace std;


class CarHandle{
PointerPropertyBuilderByName(CarHandle,carhandle,protected)
public:
    virtual void HandleCar()=0;
public:
    //接口实现类必须的一个对象，下一个责任链
    CarHandle *setNextHandle(CarHandle* carhandle){
        this->m_carhandle=carhandle;
    }
};

class CarHandleHead:public CarHandle{
public:
    void HandleCar(){
        cout<<"处理车头"<<endl;
        if(this->m_carhandle!=NULL){
            m_carhandle->HandleCar();
        }
    }
};

class CarHandleBody:public CarHandle{
public:
    void HandleCar(){
        cout<<"处理车身"<<endl;
        if(this->m_carhandle!=NULL){
            m_carhandle->HandleCar();
        }
    }
};

class CarHandleTail:public CarHandle{
public:
    void HandleCar(){
        cout<<"处理车尾"<<endl;
        if(this->m_carhandle!=NULL){
            m_carhandle->HandleCar();
        }
    }
};

int main_car()
{
    CarHandleHead *chead = new CarHandleHead;
    CarHandleBody *cbody = new CarHandleBody;
    CarHandleTail *ctail = new CarHandleTail;

    chead->setNextHandle(cbody);
    cbody->setNextHandle(ctail);
    ctail->setNextHandle(NULL);

    chead->HandleCar();

    delete ctail;
    delete cbody;
    delete chead;
    return 0;
}


#endif // CHAIN_H
